package com.example.wangzh.developkit.adapter;

import android.content.Context;
import android.graphics.Color;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.wangzh.developkit.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wangzh on 2017/12/5.
 */

public class SelectTextAdapter extends BaseSelectAdapter<SelectTextAdapter.ViewHolder> {
    Context context;
    List<String> strList;

    public SelectTextAdapter(Context context, List<String> strList) {
        this.context = context;
        this.strList = strList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context)
                .inflate(R.layout.list_item_select_text, parent, false);
        //这里建议直接inflate进parent,否则item布局的match_parent会失效
        //最后一个参数填false，否则会报错
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public int getItemCount() {
        return strList.size();
    }

    @Override
    protected void customBindViewHolder(ViewHolder holder, int position) {
        if (position == getSelectItemId()) {
            holder.txt.setTextColor(Color.RED);
        } else {
            holder.txt.setTextColor(Color.BLACK);
        }
        holder.txt.setText(strList.get(position));
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt)
        TextView txt;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        ;
    }
}
